package com.qingshu.controller.custom;

import com.qingshu.common.annotation.Log;
import com.qingshu.common.entity.custom.Music;
import com.qingshu.common.entity.custom.Singer;
import com.qingshu.common.entity.custom.model.MusicAddModel;
import com.qingshu.common.enums.BusinessType;
import com.qingshu.common.util.body.JsonResult;
import com.qingshu.common.util.body.ResultTool;
import com.qingshu.common.util.model.ModelUtil;
import com.qingshu.service.ISingerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Huzz
 * @since 2021-12-09
 */
@Api(tags = "歌手管理")
@RestController
@RequestMapping("/custom/singer")
public class SingerController {

    @Autowired
    private ISingerService singerService;

    @Log(title = "歌手业务-添加歌手", businessType = BusinessType.INSERT, isSaveResponseParam = true)
    @ApiOperation(value = "添加歌手")
    @PostMapping("/addSinger")
    public JsonResult addSinger(@RequestBody Singer model){
        return singerService.addSinger((Singer) ModelUtil.toEntityStatic(model, Singer.class)) ? ResultTool.success() : ResultTool.fail();
    }

    @Log(title = "歌手业务-根据id进行查询", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据id进行查询")
    @GetMapping("/findSingerById")
    public JsonResult findSingerById(Integer singerId){
        return ResultTool.success(singerService.findSingerById(singerId));
    }

    @Log(title = "歌手业务-根据名字进行查询", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据名字进行查询")
    @GetMapping("/findSingerByName")
    public JsonResult findSingerByName(@RequestParam String name){
        return ResultTool.success(singerService.findSingerByName(name));
    }

}
